package com.wxg.audio;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

import javazoom.jl.player.Player;

/**
 * 代码摘抄自： 
 * http://blog.sina.com.cn/s/blog_025270e90101nrxj.html
 * 
 * 其实在"http://www.javazoom.net/mp3spi/documents.html"上有完整的代码样例
 * 但是没有这里的代码简洁！
 * 
 * jar包下载自:
 * http://www.javazoom.net/mp3spi/documents.html
 * 
 * `com.wxg.audio.PlayerMusic`需要"jmf.jar"(不能运行,报错！)
 * `com.wxg.audio.MP3Player`需要"jl1.0.1.jar,tritonus_share.jar,mp3spi1.9.5.jar"
 * 
 * @author pactera
 *
 */
public class MP3Player {

	public MP3Player(String filename) {
		this.filename = filename;
	}

	public void play() {
		BufferedInputStream bis = null;
		try {
			try {
				bis = new BufferedInputStream(new FileInputStream(filename));
				player = new Player(bis);
				player.play();
			} catch (Exception e) {
				System.out.println(e);
			} finally{
				if(null != bis){bis.close();}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		String path = "C:\\Users\\pactera\\Desktop\\444\\world_en.mp3";
		MP3Player mp3 = new MP3Player(path);
		mp3.play();
	}

	private String filename;
	private Player player;
}
